package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.db.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
public interface LogMapper extends BaseMapper<Log> {

    //1.今日注册、登录
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time = #{logTime} AND type = #{type}")
    Integer countRegAndLog(@Param("logTime") String logTime, @Param("type") String type);

    //2.今日活跃
    @Select("SELECT COUNT(DISTINCT user_id) from tb_log WHERE log_time = #{logTime} ")
    Integer countActive(String logTime);

    //3.次日留存(昨天注册的，并且今天还活跃的用户)
    @Select("SELECT count(DISTINCT user_id) FROM tb_log WHERE log_time = #{today}" +
            "AND user_id in(SELECT DISTINCT user_id FROM tb_log WHERE log_time = #{yesterday} AND type = '0102')")
    Integer countRetention1d(@Param("today") String today, @Param("yesterday") String yesterday);





}